#!/bin/sh

usage() {
  echo "CernVM-FS strip of file catalog signature"
  echo "Usage: cvmfs_unsign <checksum file>"
  echo
}


CHECKSUM=$1
WORKING="$CATALOG.uncompressed"

if [ "x$CHECKSUM" == "x" ]; then
   usage
   exit 1
fi

cvmfs_zpipe -d < "$CHECKSUM" > "$WORKING"
if [ $? -ne 0 ]; then
   echo "$CHECKSUM invalid"
   rm -f "$WORKING"
   exit 1
fi

head -1 "$WORKING" | grep "[a-z0-9]\{40\}\(E[a-z0-9]\{72\}\)\{0,1\}" > /dev/null
if [ $? -ne 0 ]; then
   echo "$CHECKSUM invalid"
   rm -f "$WORKING"
   exit 1
fi

head -1 "$WORKING" | cvmfs_zpipe > "$CHECKSUM"
rm -f "$WORKING"
